﻿package {

/**
 *
 *
 *my1flex utils class
 *
 *
 *
 */
 
 import mx.controls.Alert;
 import flash.events.MouseEvent;
 import flash.utils.ByteArray;
	 
	
	public class my1flex {
 	
 	
	 	public static var ver_:String = '1.0';
	 	
	 
	 
		public static function info_(sd, sc) {
	
			 Alert.show('my1flex utils v' + ver_);
		}
		
		
		
		
			 
		public static function strstr(sd, sc) {
			var index = sd.toString().indexOf(sc);
			return index > -1 ? sd.substring( index ) : null;  
		}
		
		
		public static function stristr(sd, sc) {
			var index = sd.toString().toLowerCase().indexOf(sc.toLowerCase());
			return index > -1 ? sd.substring( index ) : null;  
		}
		
		
		public static function allob(ob) {
			for (var i in ob)
					trace(i + " : " + ob[i]);	
		}
		
		
		public static function isE(ob, class_){
			return class_.prototype.isPrototypeOf(ob); 
			//trace (a);
		}
		
		public static function a(s){
				trace (s);
		}
		
		/*public static function dump(ob, bord="") {
					for (var i in ob)
							if (typeof ob[i] == 'object') {
							 	trace (bord + i + "->");
							  	dump(ob[i], bord+i.toString().replace(/[\S\s]/g,' ')+' ');
							} 
							   else trace( bord + i + ' : ' + ob[i], typeof ob[i]);	
				}
		*/
		
		
		public static function dump(ob, bord="", s="") {
					for (var i in ob)
							if (typeof ob[i] == 'object') {
							 	trace (bord + i + "->");
							 	s += bord + i + "->\n";
							  	s = dump(ob[i], bord+i.toString().replace(/[\S\s]/g,' ')+' ', s);
							} 
							   else {
							   	 trace( bord + i + ' : ' + ob[i], typeof ob[i]);	
							   	 s += bord + i + ' : ' + ob[i] + ' ' + typeof ob[i] + '\n';
							   }
			     return s;
				}
				
				
		public static function dumpl(ob, tit=''){
			
				showArea( dump(ob), tit );
					
		}
		
		public static function showArea(text, tit=''){
			
				import mx.core.FlexGlobals;
				import mx.managers.PopUpManager;
				import mx.controls.TextArea;
				import spark.components.TitleWindow;
				 
				var fl = FlexGlobals.topLevelApplication;
				var win:TitleWindow = new TitleWindow();
				var area:TextArea = new TextArea();
				
				if (tit) area.text = tit + '\n-------------------------------------\n';
				
				area.text += text;
				
				area.width = win.width = fl.width;
				area.height = (win.height = fl.height) - 50;
				
				
				win.addEventListener("close", function(){ PopUpManager.removePopUp(win) });
				win.addElement(area);
				
							
	 			PopUpManager.addPopUp(win, fl, true); 
			    //PopUpManager.centerPopUp(pop); 
					
		}
		
		
		public static function isA(ob) {
		    return Array.prototype.isPrototypeOf(ob);
		  }
		
		
		public static function isF(ob) {
			// alter -  obj is Function
		    return Function.prototype.isPrototypeOf(ob);
		    
		   }
		
		public static function isO(ob) {
		  	  //return Object.prototype.isPrototypeOf(ob); // no work!
		  	  	return typeof ob == 'object'; 
		   }
		
		
		/*public static function cpyob (d,s, noreplace = false) {
			   for (var p in s) {
					   if (s[p] is Object && !(s[p] is Function)) {
						   if ((!(p in d) && noreplace) || !noreplace)	{ 
							   			d[p] = s[p] is Array ? [] : {};
							   			cpyob(d[p],s[p], noreplace);
							   		}
					   } else {
						   		if ((!(p in d) && noreplace) || !noreplace) {
						   			d[p] = s[p];
						   		}
						   }
			   }
		   }
		*/
		
		public static function cpyob (d,s, noreplace = false) {
		   for (var p in s) {
				   if (isO(s[p]) && !isF(s[p])) {
					   if ((!(p in d) && noreplace) || !noreplace)	{ 
						   			d[p] = d[p] != undefined ? d[p] : (isA(s[p]) ? [] : {});
						   			cpyob(d[p],s[p], noreplace);
						   		}
				   } else {
					   		if ((!(p in d) && noreplace) || !noreplace) {
					   			d[p] = s[p];
					   		}
					   }
		   }
	   }
	   
	   /*
	    * ++++
	    * 
	    * 	import mx.utils.*;
		       		
			var ci:Object = ObjectUtil.getClassInfo(loc);
			my1flex.dumpl(ci);
	    * 
	    * 
	    * 
	    */
	   
	
	
		public static function getFirstKey (ob) {
		   		for (var i in ob); 
		   		return i;
	   }
	   
		
		//оболочка 
		public static function gcpyob(s, noreplace = false){
			var d = {};
			cpyob(d, s, noreplace);
		  return d;	
		}
		
		
		
		public static function cloneob(ob){
			var res = {};
			cpyob(res, ob);
			return res;
		}
		
		public static function getser(ob, infun = false):String {
			  var s:String;
			  isA(ob) ? s = "[" : s = "{";
			  for (var p in ob)
				  if (!isF(ob[p]) || infun) {
					if (typeof ob[p] == "object") {
							s+= (s.charAt(0)=='{' ? p+":" : "") + getser(ob[p]) + '|';
					}
							else	{
								s+=(s.charAt(0)=='{' ? p+":" : "") + ob[p]  +'|' ;
							}
				  }
			  s = (s.length > 1?s.substring(0,s.length-1):s) + (isA(ob) ? s = "]" : s = "}");
			  return (s);
		}
		
		
		
		
		public static function getuser(s:String):Object {
		 	
		   function getpar(par)	{
				   var ops = 0;
				   var opq = 0;
				   var res = [];
				   var g = "";
				   for (var i = 0; i<par.length; i++) {
					    if (par.charAt(i) == "{") 	ops++;
					    if (par.charAt(i) == "[")   opq++;
					    if (par.charAt(i) == "}") 	ops--;
					    if (par.charAt(i) == "]")  opq--;
					    if (par.charAt(i)=="|" && ops==0 && opq==0) {
					    	res.push(g);
					    	g="";
					    	continue;
					    }
					    g+=par.charAt(i);
				   }
				   if (g!="") res.push(g);
				   return (res);		   
			   }
			   
			 	
			  var ob;
			  
			  s = s.replace(/[\r\s\n]+$/,"");
			  
			  s.charAt(0)=="[" ? ob = [] : ob = {};
			  //a("1",s);
			  var m = getpar(s.substring(1,s.length - 1));
			  for (var i = 0; i<m.length; i++) {
				  if (m[i].charAt(0)=="[" || m[i].charAt(0)=="{") {
					  ob[i] = getuser(m[i]);
				  }
				  else {
					  var m2 = m[i].match(/([\.\s\&\$\#\-\`\w\/]+)\:?([\s\S]+)?/).slice(1);
					  if (m2[1] && (m2[1].charAt(0) == '[' || m2[1].charAt(0) == '{')) {
						  ob[m2[0]] = getuser(m2[1]);
						  //if (m2[0]=='forseK1K2') a();
					   }  else {
					   			if (s.charAt(0) == "[") {
				   						m2[1] = m2[0];
				   						m2[0] = i;
				   					 }
				   			//if (m2[1] && m2[1].indexOf("function") > -1) 
				   				//eval("ob[m2[0]] = " + (m2[1]));
		 		   			 		//else  
		 		   			 			//if(m2[1] != undefined) ob[m2[0]] =  m2[1].toString().match(/^[\d\.\-]+$/) || m2[1]=='0'  ?  parseFloat(m2[1]) : m2[1];
										//if(m2[1] != undefined) ob[m2[0]] =  parseFloat(m2[1].toString()) || m2[1]=='0'  ?  parseFloat(m2[1]) : m2[1];
										if(m2[1] != undefined) ob[m2[0]] =  m2[1].toString().match(/^[\-\d\.]+$/)  ?  parseFloat(m2[1]) : m2[1];
				   				
				   			}
				  }
			  }
			  return (ob);
		  }
		
		
		
		/*
		function getserlua(ob, infun = false, recurse = true, except="", offsindex=0):String {
			  var s:String;
			  s = "{";
			  if (isA(ob)) var isa = true;       
			  for (var p in ob)
				  if ((!isF(ob[p]) || infun) && !stristr(except, p.toString())) {
					if (typeof ob[p] == "object") {
						if (!recurse) continue;
							s+=  ( p is Number ? '['+(p+offsindex)+']=' : p+'=' ) + getserlua(ob[p], infun, recurse, except, offsindex);
						}
							else { 
								s+= (p is Number ? '['+(p+offsindex)+']=' : p+"=")+ (typeof ob[p] == "string" ?  '"'+ob[p]+'"'  : ob[p]) +';' ;
							}
				  }
			  return (s+"};");
		}
		*/
		
		public static function getserlua(ob, infun = false, recurse = true, except="", offsindex=0):String {
			  var s:String;
			  s = "{";
			  if (isA(ob)) var isa = true;       
			  for (var p in ob)
				  if ((!isF(ob[p]) || infun) && !stristr(except, p.toString())) {
					var hh = p.toString().charAt(0)=='"';  
					if (typeof ob[p] == "object") {
						if (!recurse) continue;
						//if (p.charAt(0)=='"') p = parseInt(p.substr(1));
							s+=  ( p is Number || hh ? '['+(p+(hh?"":offsindex))+']=' : p+'=' ) + getserlua(ob[p], infun, recurse, except, offsindex);
						}
							else { 
								s+= (p is Number || hh ? '['+(p+(hh?"":offsindex))+']=' : p+"=")+ (typeof ob[p] == "string" ?  '"'+ob[p]+'"'  : ob[p]) +';' ;
							}
				  }
			  return (s+"};");
		}
		
		
		
		public static function getuserlua(s:String):Object {
		
			function getpar(par)	{
				   var ops = 0;
				   var opq = 0;
				   var res = [];
				   var g = "";
				   for (var i = 0; i<par.length; i++) {
					    if (par.charAt(i) == "{") 	ops++;
					    if (par.charAt(i) == "[")   opq++;
					    if (par.charAt(i) == "}") 	ops--;
					    if (par.charAt(i) == "]")  opq--;
					    if (par.charAt(i)==";" && ops==0 && opq==0) {
					    	res.push(g);
					    	g="";
					    	continue;
					    }
					    g+=par.charAt(i);
				   }
		
				   if (g.length>1 && !g.match(/^\s+$/)) res.push(g);
				   return (res);		   
			   }
			   
			 	
			  var ob;
			  //s.charAt(0)=="[" ? ob = [] : ob = {};
			  s = s.replace(/[\r\s\n]+$/,"");
			  //ob = s.match(/^\{[\r\n\s\t]*\[/) ?  [] : {};
			  var isA  = s.match(/^\{[\r\n\s\t]*\[/);
			  ob = {};
				//trace(s, s.match(/^\{[\r\n\s\t]*\[/));								  
			  var m = s.charAt(0)=="{" ? getpar(s.substring(1,s.length - 2)) : getpar(s);
			  //var m = s;
			 // trace("m = ",m);
			  for (var i = 0; i<m.length; i++) {
				  if (m[i].charAt(0)=="{") {
					  ob[i] = getuserlua(m[i]);
				  }
				  else {
					  if (m[i].toString().indexOf('=')>-1)
						  var m2 = m[i].match(/([\[\]\.\&\$\#\-\`\w\/\'\"]+)\s*\=\s*([\s\S]+)?/).slice(1);  							    //"'
								else m2 = [m[i], undefined];  
					  //m2[1]=m2[1].replace(/[\r\s\n]+$/,"");			
					  //trace("m2 = ",m2, ob is Array);
				      if (m2[1] && (m2[1].charAt(0) == '[' || m2[1].charAt(0) == '{')) {
						  //if (m2[0]=='forseK1K2') a();
						 //m2[0].charAt(0) == '[' ?  ob[ parseInt(m2[0].match(/\d+/))-1] =  getuserlua(m2[1]) :  ob[m2[0]] =  getuserlua(m2[1]); 
						 //trace(m2, m2[0].match(/\w+/));
						 m2[0].charAt(0) == '[' ?  ob[m2[0].match(/\w+/)]  =  getuserlua(m2[1]) :  ob[m2[0]] =  getuserlua(m2[1]);
						 // ob[m2[0]] = getuserlua(m2[1]);
					   }  else {
					   			//if (ob is Array) {
					   			if (isA) {
										//trace("mm2",m2,i);
				   						//m2[0] = m2[0].match(/\w+/);
				   						m2[0] = m2[0].match(/[\w\'\"]+/);                                                       //"'
				   						//m2[0] = parseInt(m2[0].match(/\d+/))-1;
					   					// a(m2[0]);
					   					//a("Ssssssssssss");
				   					 }
										if(m2[1] != undefined) ob[m2[0]] =  m2[1].toString().match(/^[\-\d\.]+$/)  ?  parseFloat(m2[1]) :  m2[1].charAt(0)=="'" || m2[1].charAt(0)=='"' ? m2[1].substring(1,m2[1].length-1) : m2[1].match(/^(false|true)$/) ? m2[1] == "true" : m2[1]; 
				   							else ob[m2[0]] = undefined;
				   			}
				  }
			  }
			  return (ob);
		  }
		
		
		
		public static function resetindex(ob, beginindex=1){
							var n = beginindex;			 
							var ob2 = {};
							for (var i in ob) ob2[i is Number ? n++ : i] = ob[i];
							for (i in ob) delete ob[i];
							for (i in ob2) ob[i] = ob2[i];
		}	
		
		
		public static function countOb(ob){
							var n = 0;			 
							for (var i in ob) n++;
						return n;	
		}
		
		public static function toArray(ob){
				var res = [];
				for each(var p in ob) res.push(p); 
			return res;	
		}				
		
		
		public static function delp(ob, el/*or n array*/, ri=1){
			if (ob.splice) ob.splice(el, 1);	
				else delete ob[el];
				if (typeof ri == 'number') resetindex(ob, ri);
		}
		
		public static function addp(ob, value, offsetindex=1 ){
			//dump(gettranc(ob));
			if (ob.push) ob.push(value);	
				else 
					ob[getFirstUniq(gettranc(ob), null, offsetindex)] = value;
		}
		
		
		public static function appendp(ob, value, offsetindex=1){
			if (ob.push) ob.push(value);	
				else { 
					var k = 0;
					for (var i in ob) if (i is Number && i>k) k = i;
					 ob[k + offsetindex] = value; 
				}
			return 	k + offsetindex;
		}
		
		
		/*
		 * gg.ff = 1; gg.aa="ss"; .....   
		 * 
		 */
		public static function getLuaSave(ob, pref){
			var s ="";
			for (var i in ob)
				if (typeof ob[i] == "object") 
					s+= getLuaSave(ob[i], pref+ (ob is Array ? '['+(i+1)+']' : '.'+i));
				else	
					s+= pref + (ob is Array ? '['+(i+1)+']=' : '.'+i+"=") + (typeof ob[i] == "string" ?  '"'+ob[i]+'"'  : ob[i]) +';' ;
		 return s;			
		}
		
		
		
		
		
		
		
		/**
		*@version 2
		*/
		public static function basename(s, sl:String = "/\\"){
			var n = s.length;
		  	while (n--) 
		  		if (sl.indexOf(s.charAt(n)) > -1)   { s = s.substring(++n, s.length);  break;}
		  		
		  return s;		
		}
		
		public static function dirname(dir) {
				return dir ? dir.match(/(.+)[\\\/][\-\w\.\!]*$/)[1] : "____________________";
		}
		
		//dir 0
		public static function hostname(dir) {
					return dir ? dir.match(/(http\:\/\/)?([\w\-\.]+)/)[2] : "____________________";
		}
		
		
		
		public static function haschi(ob){
				return "numChildren" in ob && ob.numChildren;
		}
		
		
		/**
		 * var mm = hasparent(comb1.getChildByName('instance22'),"s");
		  if (mm.length) ... 
		 * 
		 */
		  
		public static function hasparent(ob, ename = "*"){
			var m = [];
			var msub = ename.split(",");
			while((ob = ob.parent)) {
				   for (var n=0; n<msub.length; n++)
		   		   if (stristr(ob.toString(), msub[n]) || ename == "*") m.push(ob);
			}
			return  m;
		}
		
		
		
		/**
		 * 
		 * 		var setEnabled = function(ch){
							getchi(place, "*", false, null, function(el){
								if ("enabled" in el){
									el.enabled = ch;
									//el.alpha = el.enabled ? 1 : 0.3; 
								}
							});
						};
		 * 
		 * 
		 */
		/*public static function getchi(ob, ename = "*", recurse=false, m:Array=null, fcall = null) {
			
			import 	flash.display.DisplayObjectContainer;
			
			if (!m) m = [];
			var i = haschi(ob);
			var msub = ename.split(",");
			while(i--) {
				var chi = ob.getChildAt(i);
				for (var n=0; n<msub.length; n++){
					//if (recurse && haschi(chi)) m = getchi(chi, msub[n], true, m, fcall);
					if (chi is DisplayObjectContainer) m = getchi(chi, msub[n], true, m, fcall);                  //!!!!!!!!!!!!!!!!!!!!!!!!!!
					//a(chi.toString());
					if (stristr(chi.toString(), msub[n]) || ename == "*"){
						if (fcall) fcall( chi );				
						m.push(chi);
					 }
						
		        }
			}
		  return(m);	
		}
		*/
		
		
		public static function setsize(ob, size = 12){
			
				import flash.text.TextFormat; 
			
				var tf:TextFormat = new TextFormat();
			tf.size = size;
			ob.setStyle("textFormat", tf); 
			return tf;
		}
		
		
		
		public static function printm  (mob, recurse=false, s="") {
			var m = getchi(mob, "*");
			for (var i=0; i<m.length; i++) {
				trace(s + i + " : " + m[i] + " : " + m[i].name +  ("text" in m[i] ? " text = "+m[i].text : "") + ("label" in m[i] ? " label = "+m[i].label : ""), "index=" + m[i].parent.getChildIndex(m[i]) );
				if (recurse && haschi(m[i])) printm(m[i], true, s + "    "); 
			}
		}
		
		
		
		public static function getform(ob, context, ename = "*", recurse = false){
			var res = {};	
			var mel = [
							'[object TextInput]',
							'[object ComboBox]',
							'[object CheckBox]',
							'[object RadioButton]',
							'[NumericStepper]'
						 ];
						 
			var m = getchi(context.parent, ename, recurse);
			for (var i=0; i<m.length; i++){
			    	//if ("text" in m[i]) res[m[i].name] = m[i].text;
			    if (!hasparent(m[i], mel.join()).length)
					switch (m[i].toString()){
							case  mel[0]  :
							case  mel[1]  : 
														 res[m[i].name] = m[i].text;//  res[m[i].name + '_ob'] = m[i];  
									   					 break;
							case  mel[2]  :
							case  mel[3]  : 
														 res[m[i].name] = m[i].selected;  
									   					 break;
					}
				
			}
			return res;
		}
		
		
		public static function setform(ob, prop, context/*this*/, recurse = false){
			var mel = [
							'[object TextInput]',
							'[object ComboBox]',
							'[object CheckBox]',
							'[object RadioButton]'
						 ];
						 
			var m = getchi(context.parent, "*", recurse);
			for (var i=0; i<m.length; i++){
				
					switch (m[i].toString()){
							case  mel[0]  :
							case  mel[1]  : 
														 m[i].text = prop[m[i].name] || m[i].text;  
									   					 break;
							case  mel[2]  :
							case  mel[3]  : 
														 m[i].selected = prop[m[i].name];  
									   					 break;
					}
				
			}
		}
		
		
		
		
		
		
		public static function anime0(ob, step, start, stop, speed, display_show_property=null, fun_end=null){
		
		import flash.utils.*;
		
		var i=start;
		var inc, iid;
		var deb ="";
		
		speed = speed || 10;
		
		start>stop ? inc=0 : inc=1;
		
		function hide() {
			//if (ob.className == "divpanprog") alert(deb);
			//if (display_show_property){
		//		ob.style.display="none";
		//	} else {
		//		ob.style.visibility="hidden";
		//	}
			ob.visible= false;
		}
		
		   function hhi(){
			inc ? i+=step : i-=step;
				//alert(i+"__"+step);
				
			if (i-step<0) hide();
		
			if ((i>stop && !inc) || (i<stop && inc)) {
				//curopop=i;
				//deb+=i+"__"+step+"\n";
				//a(i);
				ob.alpha = i;
				//window.setTimeout(hhi,speed);
			} else {
				//alert("ssssssss");
				//if (ob.className == "divpanprog") alert(deb);
				if (fun_end) fun_end.call();
				clearInterval (iid);
			}
		   }
		
		     //hhi();
		    iid = setInterval(hhi, speed);
		
			if (start==0) {
			//if (display_show_property)
				//ob.style.display=display_show_property;
					//else
					ob.alpha = 0;  
					ob.visible = true;
		}
			
		
		    
		   return iid; 
		}
		
	
	
	/*	
		//position
		
		
		public static function getxy(ob) {   
			var x = 0, y = 0;
			while (ob) {
				x+=  ob.x;
				y+=  ob.y;
				ob = ob.parent;
			}
			return {x:x,
					y:y};
		}
		
		
		public static function alxy(ob,x=0,y=0, cx=0,cy=0){
			if (!(x is Number)) { y=x.y;  x=x.x;}
			ob.x = x+cx; ob.y =y+cy;
		}
		
		
		public static function alxyg(ob,x=0,y=0, cx=0,cy=0){
			//if (!(x is Number)) { y=x.y; x=x.x;}
			if (!(x is Number)) { y=x.localToGlobal(new Point(0, 0)).y;  x=x.localToGlobal(new Point(0, 0)).x;	}
			//if (!(x is Number)) { y=getxy(x).y; x=getxy(x).x;}
			//if (!(x is Number)) { y=x.localToGlobal(new Point(0, 0)).y; x=x.localToGlobal(new Point(0, 0)).x;}
			//ob.x=ob.globalToLocal(new Point(0, 0)).x;  ob.y=ob.globalToLocal(new Point(0, 0)).y; 
			ob.x = x+cx; ob.y =y+cy;
		}
		
		public static function alxyl(ob,x=0,y=0, cx=0,cy=0){
			if (!(x is Number)) { y=x.globalToLocal(new Point(0, 0)).y;  x=x.globalToLocal(new Point(0, 0)).x;}
			ob.x = x+cx; ob.y =y+cy;
		}
		
		
		
		
		public static function al_siz(ob,w=0,h=0, cw=0,ch=0){
			if (!(w is Number)) { h=w.height; w=w.width;}
			//if (!(x is Number)) { y=x.localToGlobal(new Point(0, 0)).y; x=x.localToGlobal(new Point(0, 0)).x;}
			//ob.x=ob.globalToLocal(new Point(0, 0)).x;  ob.y=ob.globalToLocal(new Point(0, 0)).y; 
			ob.width = w+cw; ob.height = h+ch;
		}
		
		
		public static function al_sc(ob,x,y=0){
			if (!(x is Number)) { y=x.scaleY; x=x.scaleX;}
				else if (!y) y = x;
			ob.scaleX = x;
			ob.scaleY = y;
		}
		
		
		//test
		public static function al_r(ob, cx=0, cy=0){
				
				import mx.core.FlexGlobals;
				
				var cot = FlexGlobals.topLevelApplication.stage.stageWidth;
			///ob.x = ob.parent.globalToLocal(new Point(stage.stageWidth - ob.width,0)).x + cx;
			//var rwork = stage.stageWidth;
			//ob.x = (ob.parent.localToGlobal(new Point(0, 0)).x) + stage.stageWidth - ob.width +  cx;
			  ob.x =  cot - ob.width +  cx;	 	
		}
		
		
		public static function al_ca(l,cx=0, cy=0){
			
				
				import mx.core.FlexGlobals;
				
				var r = function(){
				  l.x =  (FlexGlobals.topLevelApplication.stage.stageWidth - l.width) / 2 + cx;
			  	  l.y =  (FlexGlobals.topLevelApplication.stage.stageHeight - l.height) / 2 + cy;
			};
		FlexGlobals.topLevelApplication.stage.addEventListener("resize", r);
		return r;
		}
		
		
		public static function al_b(ob, cx=0, cy=0){
			
			import mx.core.FlexGlobals;
			
			var cot = FlexGlobals.topLevelApplication.stage.stageHeight;
			if (!(cx is Number))  cot = cx.height;
			//ob.y =   inplace.globalToLocal(new Point(0, 0)).y + (stage.stageHeight - ob.height);
			//ob.y = ob.parent.localToGlobal(new Point(0, stage.stageHeight - ob.height)).y + cy;  //(stage.stageHeight - ob.height);
			ob.y =  cot - ob.height +  cy;
		}
		
		
		
		public static function al_c(ob, inobxy=null,  cx=0, cy=0){
			
			import mx.core.FlexGlobals;
			
			if (!inobxy) inobxy = FlexGlobals.topLevelApplication.stage;
						else inobxy = {stageWidth : inobxy.width, stageHeight : inobxy.height};  
						
				ob.x = (inobxy.stageWidth - ob.width) / 2  + cx;
		    	ob.y = (inobxy.stageHeight  - ob.height) /2  + cy;
		}
		
		
		
		
		//test
		public static function al_r2(ob,  cx=0, cy=0){
			ob.x = getxy(ob.parent).x;// - ob.width + cx;
			ob.y+= cy;
		}
		
		*/
		
		
		//events
		/*
		 * 
		 * постоянно для элемента
		 * ----------------------------
		 * setblur(infsen, changePropSensor, 2000, "onlyChange");
		 * 
		 */
		
		public static function setblur(mob, fun, tim=5000, onlyChange=false, closeClickSelf=false){
			
			import flash.utils.*;
			import mx.core.FlexGlobals;
			
			
			if (!isA(mob)) mob = [mob];
			var fStageClick;
			var fChange;
			var id;
			
			var __ismainele = function(e) {
				for (var i=0; i<mob.length; i++) if (mob[i].contains(e.target)) return true;
				return false;
			};
			
			var __whiteforaction = function(e) {
				if (id) clearTimeout(id);
				id = setTimeout(function(){ /*a("fc=="+fChange);*/ if (fChange) fun(); if (onlyChange) fChange = false;  if (fStageClick) FlexGlobals.topLevelApplication.stage.removeEventListener(MouseEvent.CLICK ,stagee); fStageClick=false;  }, tim);
				if (!fStageClick) 
					FlexGlobals.topLevelApplication.stage.addEventListener(MouseEvent.CLICK ,stagee);
				fStageClick = true;
			}
			
			
			mob[0].addEventListener(MouseEvent.ROLL_OUT, __whiteforaction);
			
			mob[0].addEventListener(MouseEvent.ROLL_OVER ,function(){	
				clearTimeout(id);	
			});
			
			
			if (onlyChange)
				mob[0].addEventListener("change" ,function(){if (fChange) return;   fChange = true;  __whiteforaction()});
			else fChange = true;
			
			var stagee = function(e){
				//a("st click");
				//if (__ismainele(e) && !closeClickSelf) return;
				if (__ismainele(e)) return;
				//a("dddddddddddddd");
				fStageClick = false;
				clearTimeout(id);
				FlexGlobals.topLevelApplication.stage.removeEventListener(MouseEvent.CLICK ,stagee);
				if (fChange) fun.call();
				if (onlyChange) fChange = false;
			};
			
			
			var forse = function(){
				
			};
			
			
		
		}
		
		
		
		
		/**
		 * ------------------------------ 
		 * shine([o.sb,o.me],0.01,0.1, 0.4);
		 * 
		 */
		public static function shine(ob, stepD=0.02, stepS=0.1, dimlyQ=0.4) {
		
			var di;
			
				var shiniest = function (){
					if (di === true){
						 anime0(ob,stepD,dimlyQ,1,1, null, function(){ di = false; trace(di); });
						 di = 0;
					}
				};
				var dimly = function (){
					if (di === false){
						 anime0(ob,stepD,1,dimlyQ,1, null, function(){  di = true; trace(di); });
						 di = 0;
					}
				};	
				
				ob.addEventListener(MouseEvent.ROLL_OVER,shiniest);
				ob.addEventListener(MouseEvent.ROLL_OUT,dimly);
			
			  function forsedimly() {
				 	anime0(ob,stepD,1,dimlyQ,1, null, function(){ di = true;});
			  }
			forsedimly();		  
		}
		
		public static function addev(el, ev, fun){
				/*
					rollOut
					rollOver
					mouseWheel
					mouseOut
					mouseMove
					doubleClick
				*/
				el.addEventListener(ev, fun, false);
		}
		
		
		public static function remchi(ob){
			if (ob.numChildren) while (ob.numChildren - 1) ob.removeChildAt(1);	
		}
		
		public static function remchi_2(ob){
			while (ob.numChildren) ob.removeChildAt(0);
		}
		
		
		/*
		 * 
		 * var t:TextFormat = new TextFormat();
			t.underline = true;
		
		this.addEventListener("rollOver", function(){
			oo.setStyle("textFormat", t);
		});
		
		this.addEventListener("rollOut", function(){
			oo.setStyle("textFormat",null);							   
		});
		 * 
		 */
		 
		public static function drag(ob, activ=false, exceptChild=null, funMove=null){
			//mm.buttonMode = true;
			ob.addEventListener(MouseEvent.MOUSE_DOWN, down);
			ob.addEventListener(MouseEvent.MOUSE_UP, up);
			if (funMove){
				ob.addEventListener(MouseEvent.MOUSE_MOVE, function(e){
						funMove.call(this, e);	
				});
			}
			
			function __ischildexp(e){
				if (e && exceptChild)
			    	for each (var i in exceptChild)
			    		if (i === e.target) return true; 
			    return false;	
			}
			
			function down(e:MouseEvent):void {
			    //e.target.startDrag();
			    if (!__ischildexp()) 
			    		ob.startDrag();
			}
			
			//stage.addEventListener(MouseEvent.MOUSE_MOVE, dragMe);
			function dragMe(e:MouseEvent):void {
		    	e.updateAfterEvent();
			}
			
			function up(e:MouseEvent):void {
			    	ob.stopDrag();
			    	e.updateAfterEvent();
			    //a(e.stageX +"___"+ e.target.x);
			}
			if (activ) down(null);
			
		}
		
		
		
		
		/*
		//test
		function setTree(list, data){
					var xml:XML = new XML("<r></r>");
						var n = 0;			
						for (var i in data){
							var dd = xml.appendChild((new XML("<d label='"+data[i].name+"' data='"+(data[i].data ?  data[i].data : "")+"'></d>")));
								dd.children()[n].appendChild(<d label='dddd'></d>);
							n++;
						}
						
					list.dataProvider = new TreeDataProvider(xml);
		}
		*/
		
		
		
		public static function prm(ob){
			trace(ob.name, "a="+ob.transform.matrix.a.toFixed(4), "b="+ob.transform.matrix.b.toFixed(4), "c="+ob.transform.matrix.c.toFixed(4), "d="+ob.transform.matrix.d.toFixed(4), "tx="+ob.transform.matrix.tx, "ty="+ob.transform.matrix.ty,  ob.width.toFixed(0)+"x"+ob.height.toFixed(0)); 
		}
		
				
		public static function rotateAroundCenter (ob:*, angleDegrees:Number, x,y, old = null) {
			
				import flash.geom.Matrix; 
			
				var m:Matrix= old || ob.transform.matrix;
		    	  m.tx -= x;
		      	  m.ty -= y;
		      	  m.rotate (angleDegrees*(Math.PI/180));
		          m.tx += x;
		          m.ty += y;
		         ob.transform.matrix=m;
		       return(m);  
		 }
		 
		 /*
		 private function drawRotated(buffer:BitmapData, img:BitmapData, x:Number, y:Number, angle:Number = 0, scaleX:Number = 1, scaleY:Number = 1):void {
			var mat:Matrix = new Matrix();
			mat.translate(-img.width/2.0, -img.height/2.0);
			mat.scale(scaleX, scaleY);
			mat.rotate(angle);
			mat.translate(x, y);
			buffer.draw(img, mat, null, null, null, true);
		}
		}
		*/
		
		
		public static function mouseDownMove(el, fun){
			var down;
			addev(el, "mouseUp", function(){down=false;});
			addev(el, "mouseDown", function(){down=true;});
			addev(el, "mouseMove", function(e){if (down) fun.call(this, e);});
			 
		}
		 
		 
		public static function getMContrast(m=""){
			var matrix:Array = new Array();
			 switch (m){
			 	case 'many' :
			 					matrix = [0.6,0,0,0,
			 							  26,0,0.6,0,
			 							  0,26,0,0,
			 							  0.6,0,26,0,
			 							  0,0,1,0];
			 					break;
			 					
			 	
				default : 
					matrix=matrix.concat([0.5,0.5,0.5,0,0]);// red
					matrix=matrix.concat([0.5,0.5,0.5,0,0]);// green
					matrix=matrix.concat([0.5,0.5,0.5,0,0]);// blue
					matrix=matrix.concat([0,0,0,1,0]);// alpha
			}
			return(matrix);		
		}
		 
		 
		
		/*
		 * 
		 * добавление без верхней матрицы
		 */
		public static function insWEffect(ob, obin=null){
			
			import flash.geom.Matrix;
			import  flash.geom.Point;
			
				obin = obin || ob.parent;
			var mr:Matrix = obin.transform.matrix;
			var m:Matrix =  ob.transform.matrix;
			var x = m.tx, y = m.ty;
				
			//m.identity();
			m.a = mr.a;
			m.d = mr.d;
			m.b = -mr.b;
			m.c = -mr.c;
			
			m.tx = obin.globalToLocal(new Point(x,y)).x;
			m.ty = obin.globalToLocal(new Point(x,y)).y;
			
			ob.transform.matrix = m;
		}
		
		
		/*
		 * 
		 * ---------------
		 *      rc.contextMenu = getMenu([
		 *      	{label : "nik", fun : function(){ a("ss"); }}, function(){ l1.selectedItem  = e.mouseTarget.data; itemMove();  l1.contextMenu.customItems[0].enabled = parseInt(curNode.part);  } } }
		 *      ]);
		 *      ///
		 * 
		 */
		public static function getMenu(mi, funOpenMenu=null) {
			
			 import flash.ui.ContextMenu;
			 import flash.ui.ContextMenuItem;
			 import flash.events.ContextMenuEvent;
			
			
			
			/*
			  	    //Для глоб закрепления приложения flex
		            import mx.core.FlexGlobals;
		 
		            private function init():void {
		                var customMenuItem1:ContextMenuItem = new ContextMenuItem("Flex SDK " + mx_internal::VERSION, false, false);
		                var customMenuItem2:ContextMenuItem = new ContextMenuItem("Player " + Capabilities.version, false, false);
		                var contextMenuCustomItems:Array = FlexGlobals.topLevelApplication.contextMenu.customItems;
		                contextMenuCustomItems.push(customMenuItem1);
		                contextMenuCustomItems.push(customMenuItem2);
		            }
		 
			 */
			
			
			var cm:ContextMenu = new ContextMenu();
			//cm.clipboardMenu = true;
			cm.hideBuiltInItems();			   
			if (funOpenMenu)
				cm.addEventListener(ContextMenuEvent.MENU_SELECT, funOpenMenu);      //при создании
			for each(var p in mi){
				var cmi = new ContextMenuItem(p.label, false);
				cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, p.fun); 
				cm.customItems.push(cmi); 
			}		
		
		   return cm;
		}
		
		
		public static function cptoUTF(s){
			if (s){
				var ba:ByteArray = new ByteArray();			
				ba.writeMultiByte(s, "windows-1251");
				ba.position = 0;
				return ba.readMultiByte(ba.length, "utf-8");
			} 
		 return null;	
		}
		
		
		
		/*
			inf11.buttonMode = true;
			inf11.mouseChildren = false; 
		 * 
		 */
		
		
		
		
		
		
		
		
		public static function en(el, ch=true, alpha=0.2){
			
			import  mx.controls.Label;
			
			   		if (ch) {
			   			//if ("enabled" in el) el.enabled = true;
			   			//if (!(el is Label)) el.alpha = 1;
			   			 el.enabled = true;
			   			 // if (!(el is InteractiveObject) || (el is Label)) el.alpha = 1;
			  			 if (!('setFocus' in el) || (el is Label)) el.alpha = 1;
			   		} else {
			   			//if ("enabled" in el) el.enabled = false;
			   			//if (!(el is Label)) el.alpha = alpha;
			   			     el.enabled = false;
		   			// if (!(el is InteractiveObject) || (el is Label)) el.alpha = alpha;
					 if (!('setFocus' in el) || (el is Label)) el.alpha = alpha;
			   		}
		 }
			
			   
		
		public static function enall(obin, ch=true, alpha=0.2){
				getchi(obin, "*", true, null, function(el){ 
					if ("enabled" in el){ 
								el.enabled = ch;
								el.alpha = ch ? 1 : alpha;  
						}
			});	
		}
		
		
		public static function addEvEnter(el, fun, ev="keyDown"){
			
			el.addEventListener(ev, function(e){
					if (e.keyCode == 13) fun.call();		
			});
			
		}
		
		/*trace(getFirstUniq(m, "id"));
		 *
		 */
		public static function getFirstUniq(ob, prop=null, starti=0){
			var lastID = starti;
			for (var p in ob) {
				var inid = false;
				for (var p2 in ob)
					if ((prop && ob[p2][prop] == lastID) || (!prop && ob[p2] == lastID)) inid = true;   
				if (!inid)  break; 
				lastID++;
		    }
			return lastID; 	
		}
		
		
		/*
		 * trancparament ob in arr
		 * 
		 */
		public static function gettranc(ob){
			var res = [];
				for (var i in ob) res.push(i);
			return res;	
		}
		
		
		
		
		public static function isina(ob, sub, prop=null){
			for (var p in ob) if ((prop && ob[p][prop] == sub) || (!prop && ob[p] == sub)) return true;
			return false; 	
		}
		
	
		
		
		 public static function setcombo(ob, vreg, prop='', def=0, autoAdd=undefined) {
		          	
					for(var i=0; i<ob.dataProvider.length; i++) {
						var it = prop ? ob.dataProvider[i][prop] : ob.dataProvider[i]; 
						//Alert.show(it.toString()+"_________"+ vreg);
						if (it.toString().match(new RegExp(vreg))){
							ob.selectedIndex = i; 
							return i;
						} 
					}
				if (autoAdd !== undefined){
					ob.dataProvider.addItem(autoAdd);
					def = ob.selectedIndex = ob.dataProvider.length - 1;
				} else
					ob.selectedIndex = def;	
				return (def);	
		 }
		 
		 
		 public static function getIndexFromValue(ob, vreg, prop='', def=0, autoAdd=undefined) {
		 	
					import mx.utils.ArrayUtil;
		          	
		          	var m = ArrayUtil.toArray(ob);
		          	
					for(var i=0; i<m.length; i++) {
						var it = prop ? m[i][prop] : m[i]; 
						if (it.toString().match(new RegExp(vreg))){
							return i;
						} 
					}
					
				if (autoAdd !== undefined){
					def = m.length;
					if ('addItem' in ob) ob.addItem(autoAdd);
						else if (ob is Array) ob.push(autoAdd);
				} 	
				return (def);	
		 }
		 
		 
		 public static function getItemFromValue(ob, vreg, prop='', def=0, autoAdd=undefined) {
		 	
					import mx.utils.ArrayUtil;
		          	
		          	var m = ArrayUtil.toArray(ob);
		          	
					for(var i=0; i<m.length; i++) {
						var it = prop ? m[i][prop] : m[i]; 
						if (it.toString().match(new RegExp(vreg))){
							return m[i];
						} 
					}
					
				if (autoAdd !== undefined){
					def = m.length;
					if ('addItem' in ob) ob.addItem(autoAdd);
						else if (ob is Array) ob.push(autoAdd);
				} 	
				return null;	
		 }
		 
		 
		/*
		 * 
		 * old ver
		 */
		 public static function exInList(ob, vreg, vstr='', prop='') {
		 	
		 			import mx.utils.ArrayUtil;
		 			
		          	var m = ArrayUtil.toArray(ob);
		          	//Alert.show(vreg);
					for(var i=0; i<m.length; i++) {
						var it = prop ? m[i][prop] : m[i]; 
						if (vreg && it.toString().match(new RegExp(vreg)) || vstr && vstr.toString().toLowerCase() == it.toString().toLowerCase()){
							return true;
						} 
					}
				return false;	
		 }
			
			
		
		public static function setMaxii(el, min=0, max=9999, prop='text'){
			addev(el, "change", function(e){
				if (parseFloat(el[prop])>parseFloat(max) &&  !el[prop].match(/\.$/)) el.text = max; 
				if (parseFloat(el[prop])<parseFloat(min) &&  !el[prop].match(/\.$/)) el.text = min;
			});
			addev(el, "focusOut", function(e){
				if (el[prop]=="") el.text = min; 
			});
		}
		
		public static function inArr(m, v, prop=""){
			for each (var p in m) if (!prop && p == v || prop && prop in p && p[prop] == v) return true; 
			return false;
		}
		
		
		
		public static function setInputDef(el, value, colorDef=0xd3d3d3, prop="text") {
				
				import flash.text.TextFormat;
			
			    var defs = el.getStyle("textFormat");
				var news:TextFormat = new TextFormat();
				news.color = colorDef;
				news.italic = true;
			    
				addev(el,"focusIn",function(){
					if (el[prop] == value) { 
						el[prop] = "";
						el.setStyle("textFormat", defs);
					}
				});
				
				function fout(){
					if (el[prop] == "") {
						el[prop] = value;
						el.setStyle("textFormat", news);
					}
				}
				
				addev(el,"focusOut", fout);
				fout();
		}
		
		
		
		
		public static function getsort(ob, prop=null, addkeyparam=null, parse=true){
			var ob2 = {};
			if (addkeyparam) cpyob(ob2, ob); else ob2 = ob;
			function s(a,b){
					//trace('_________',a, a.toString().match(/\d+/), (!prop && parse && a.toString().match(/\d+/)  > b.toString().match(/\d+/))  );
					if (typeof a == 'object' && !prop){
						a = a._nik_;
						b = b._nik_;
					}
					return ((prop && parse && a[prop.toString().match(/\d+/)] > b[prop.toString().match(/\d+/)]) ||  
							(prop && a[prop] > b[prop]) || (!prop && a > b) ||
							(!prop && parse && a.toString().match(/\d+/) > b.toString().match(/\d+/))) ? 1 : -1;
			}
					
			var m = [];	
			for (var i in ob2) { 
				if (addkeyparam) ob2[i][addkeyparam] = i;
				if (typeof ob2[i] == 'object' && !prop) ob2[i]._nik_ = i;  
					m.push(ob2[i]); 
			}
			m.sort(s);
			
			if (!prop) for (i in m)  
							if (m[i]._nik_) delete m[i]._nik_;
			
			//dump(m);
			return m;
		}
		
		
		
		
		
		
		public static function makeob(m, prop=null){
			var ob  = {};
			//for each(var p in m) if (prop) ob[p.prop] = p;  ob[i] = m[i];
			return ob;
		}
		
		
		// --> 10.10.01 23:10
		public static function getDateSE(t, sec = false){
			var d = new Date(t);
			return  (d.getDate()<10 ? '0'+d.getDate():d.getDate() )+'.'
			+(d.getMonth()<9 ? '0'+(d.getMonth() + 1): (d.getMonth() + 1) )+'.'
			+d.getFullYear()+' '
			+(d.getHours()<10 ? '0'+d.getHours():d.getHours() )+':'
			+(d.getMinutes()<10 ? '0'+d.getMinutes():d.getMinutes() ) 
			+ (sec ? ':' + (d.getSeconds()<10 ? '0'+d.getSeconds():d.getSeconds()) : ''); 
		}
		
		
		public static function getMaxDay(t){
			var d:Date =  new Date(t);
			var i = 20;
			while (d.getDate()!=1){
				d.setDate(i);
				i++;
			}
			return i-2;
		}
		
		
		public static function getsdate(s, pt){
			var m = s.split(pt);
			var d = new Date();
			d.setFullYear(m[0]);
			d.setMonth(m[1]-1);
			if (m[2]) d.setDate(m[2]);
			return d;
		}
		
		
		public static function oneflash(el, startBlur=2, step=0.01, cFlush=0xFF0000){
			//if (!el.filters) el.filters = [];
					//el.filters.push([new GlowFilter (cFlush)]);
			
			import flash.utils.setTimeout;
			import flash.filters.GlowFilter;
			import flash.filters.BlurFilter;
					
			var m = el.filters;			
			var op = startBlur;
			var fg = new GlowFilter (cFlush, 0.1);
			var fb = new BlurFilter();
			function setop_(){  
			    op -= step;
				el.filters = [fb, fg];
				 fg.alpha = op < 1  ? op : 1;
				 fb.blurX = op;
				 fb.blurY = op;
				if (op > 0) setTimeout(setop_, 1);
			}
			setop_();
				
		}
		
		
		/*
		 	var groupm = [];
			mhint(bb, 'dddddddddddddddd',{}, groupm );
			mhint(bb3, 'cccccccccccccccccccccc',{},  groupm); 
			mhint(ll, 'dsddddddddddd', {font : (new fff()).font, fSize : 14});
		 */
		 
	/*	
		public static function mhint(el, str, opt=null, groupm = null){
			
				import flash.geom.Matrix;
				import flash.display.Sprite;
				import flash.text.TextField;
			
				if (!opt) opt = {};
					cpyob(opt,{
						  showAlways : false, 
						  durOn      : 8000, 	//активна над объектом
						  cx         : 0,
						  cy         : 0,
						  dur		 : 10,   	//активна после ухода
						  font       : 'Arial',
						  fSize      : 11,        
						  tf 		 : undefined,
						  bColor1 	 : 0xFEFE90,
						  bColor2	 : 0xFEFE90-4000,
						  ss		 : 0.2,
						  sd		 : 0.02,
						  radW       : 4,
						  radH		 : 4,
						  cLine		 : 0,	
						  //grad
						  alphas     : [1, 1],
						  ratios	 : [0x00, 0xFF]
						  //
					 }, true);
			
			
			var t:TextField = new TextField();
			t.text = str;
			t.antiAliasType = 'advanced';
			t.autoSize = 'center';
			if (!opt.tf) opt.tf =  new TextFormat(opt.font , opt.fSize);
			t.setTextFormat(opt.tf);
			
		  	var sp:Sprite = new Sprite();
			sp.cacheAsBitmap = true;
		  	var fillType:String = GradientType.LINEAR;
		  	var colors:Array = [opt.bColor1, opt.bColor2];
		  	var alphas:Array = opt.alphas;
		  	var ratios:Array = opt.ratios;
		  	var matr:Matrix = new Matrix();
		  	matr.createGradientBox(t.width, t.height, 0, 0, 0);
		  	var spreadMethod:String = SpreadMethod.PAD;
		  	sp.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
			sp.graphics.lineStyle(1, opt.cLine, 1, true);
			sp.graphics.drawRoundRect(t.x,t.y, t.width, t.height, opt.radW, opt.radH);
		    sp.addChild(t);	
			
			var di = false;
			
			el.addEventListener("mouseOver", function(){
		        forseAllDimly();											   
				if (di === false){
					alxyg(sp, el, 0, (el.width /2) + opt.cx, (el.height > 50 ? el.height / 2 : el.height + 5) + opt.cy);
					//var correctX = sp.localToGlobal(new Point(0, 0)).x - stage.width;
					var correctX = sp.x + sp.width - stage.stageWidth + 30;
					sp.x -=  correctX > 0 ? correctX : 0 ;
					anime0(sp, opt.ss, 0,2, 1, null, function(){ di = true; });
					sp.visible = true;
					stage.addChild(sp);
					di = 0;
					if (!opt.showAlways) setTimeout(function(){if (di === true) { anime0(sp, opt.sd, 1,0, 1, null, function(){ if (stage.getChildByName(sp.name))  stage.removeChild(sp); di = false; }); }  }, opt.durOn);
				}
				   
			});
			
				el.addEventListener("mouseOut", function(){
					if (di === true) {
							setTimeout(function(){anime0(sp, opt.sd, 1,0, 1, null, function(){if (stage.getChildByName(sp.name)) stage.removeChild(sp); di = false; }); }, opt.dur);
							di = 0;
						}
				});
			
			function forseAllDimly() {
				 	for (var i in groupm) groupm[i].visible = false;
			  }
	
		
		//	setblur([el], function(){ anime0(sp, 0.01, 1,0, 1, null, function(){stage.removeChild(sp); }); }, 300);
		if (groupm) groupm.push(sp);
		return sp;
		}
		
		
		public static function isCorrLua(s){
			var a = 0, b = 0;
			for (var i = 0; i < s.length; i++){
				 if (s.charAt(i) == '{') a++;
				 if (s.charAt(i) == '}') b++;
			}
			return a == b;
		}
	*/
	
		/*
		 * menu - NativeMenu
		 */
		public static function setLNative(menu, data, label, onlyDisabled=null){
				
				for each(var p in menu.items){
					if (p.data && p.data.data == data) {
							 if (onlyDisabled is Boolean) p.enabled = onlyDisabled;
							 		else  p.label = label;
						} else
							if (p.submenu) setLNative(p.submenu, data, label);
							
				}
				
		}
		
		
		public static function setIfindex(el, need = null, fun = null){
				 import flash.utils.setTimeout;
				 if (el.dataProvider) 
				 		//el.selectedIndex = Math.min(el.dataProvider.length - 1, need is Number  ? need :  el.selectedIndex == -1 ? 0 : el.selectedIndex);  
				 		setTimeout(function(){el.selectedIndex = Math.min(el.dataProvider.length - 1, need is Number  ? need :  el.selectedIndex == -1 ? 0 : el.selectedIndex);  if (fun) fun(); }, 1);
			}
	
	
		public static function dumpa(data, showN = false){
			var s = "";
			var i = 0;
			var pos = data.position;
			data.position = 0;
			while (data.bytesAvailable){
				var p = data.readUnsignedByte().toString(16).toUpperCase();
				s += ((showN ? i+':' : '') + (p.length == 1 ? '0' + p : p) + ' ');
				i++;
			}
			data.position = pos;
			return(s);
		}
		
		
		
		/*
		 * data - ByteArray or string 
		 * 
		 */
		public static function getSHA256(data, charSet='cp866'){
			import mx.utils.SHA256;
			
			if (!(data is ByteArray)){
				var dd:ByteArray = new ByteArray();
				dd.writeMultiByte(data, charSet);
				data = dd;			
			}
				return SHA256.computeDigest(data); 
		}
		
		
		public static function getSHA256File(file/*app:/*/){
			import flash.filesystem.*;
			var f = new File(file);
			var fs = new FileStream();
			fs.open(f, FileMode.READ);
			var bb = new ByteArray();
			fs.readBytes(bb);
			fs.close();
			return getSHA256(bb);
			
		}   

	/*
	 *wiki 
	 * 
	 */
		public static function getcrc(pcBlock, pos = 0, len = 0){
					var crc = 0xFFFF; 
					var oldPos = pcBlock.position; 
					pcBlock.position = pos;
					var n = len || pcBlock.length;
					while (n-- && n < pcBlock.bytesAvailable) { 
					crc ^=  pcBlock.readUnsignedByte() << 8;
					crc &= 0xffff;
						 for (var i = 0; i < 8; i++){ 
						 		crc = crc & 0x8000 ? (crc << 1) ^ 0x1021 : crc << 1;
						 		crc &= 0xffff;
						 } 
					 } 
					pcBlock.position = oldPos; 
					return crc;
			}
			
				
				
		public static function getcrcB(pcBlock, pos = 0, len = 0){
					var crc = 0xFFFF; 
					var oldPos = pcBlock.position; 
					pcBlock.position = pos;
					var n = len || pcBlock.length;
					while (n-- && n < pcBlock.bytesAvailable) { 
					crc ^=  pcBlock.readUnsignedByte();
					crc &= 0xffff;
						 for (var i = 0; i < 8; i++){ 
						 		if (crc & 1)
									crc = (crc >> 1) ^ 0xA001;
								else
									crc = (crc >> 1);
							 crc &= 0xffff;		
						 } 
					 } 
					pcBlock.position = oldPos; 
					return crc;
			}
		
		/*
		public static function getcrcB32(pcBlock, pos = 0, len = 0){
					var crc:uint = 0xffffffff;
					var oldPos = pcBlock.position; 
					pcBlock.position = pos;
					var n = len || pcBlock.length;
					while (n-- && n < pcBlock.bytesAvailable) { 
					crc ^=  pcBlock.readUnsignedByte();
					//crc &= 0xffffffff;
					//crc &= 0xff;
						 for (var i = 0; i < 8; i++){ 
						 		if (crc & 1)
									crc = (crc >> 1) ^ 0xEDB88320;
								else
									crc = (crc >> 1);
							 //crc &= 0xffffffff;		
						 } 
					 } 
					pcBlock.position = oldPos; 
					return crc;
			}
		 */
			

	public static function funAllChild(pan, fun, deep = true){
			
	        import mx.core.Container;
	        import spark.components.supportClasses.SkinnableContainerBase;
	        import spark.components.supportClasses.GroupBase;
			
			 for  (var i=0; i<pan.numElements; i++) {
			 				var chi = pan.getElementAt(i);
							if ((chi is Container || 
								chi is SkinnableContainerBase ||
								chi is GroupBase
								) && deep && 'numElements' in chi)	
								funAllChild(chi, fun, deep);
							fun(chi);	
            }
		} 



	public static function strFillBegin(s, n = 1, c = '0'){
	   		var cum = '';
			for (var i=0; i< n - s.toString().length; i++){
					cum += c;
			}
			return cum + s;	
	   }	


	public static function strFillEnd(s, n = 1, c = '0'){
	   		var cum = '';
			for (var i=0; i< n - s.length; i++){
					cum += c;
			}
			return s + cum;	
	   }	
	
	public static function maxInArr(m, prop = undefined){
	   		var max;
			for each(var p in m){
					if (prop !== undefined){
							if (parseFloat(p[prop]) > max || max == undefined) max = parseFloat(p[prop]); 
					}  else if (parseFloat(p) > max || max == undefined)  max = parseFloat(p[i]); 
				}
			return max;	
	   }	

	public static function getDateNext(base, day=0, m=0, y=0):Date{
		
				var d:Date = new Date(base);
				if (day) d.setDate(d.getDate() + day);
				if (m) d.setMonth(d.getMonth() + m);
				if (y) d.setFullYear(d.getFullYear() + y);
				return d;
		}
	

  }
}
